#pragma once

#include "Widgets/Window.h"

#include "ContextMenuWindow.m.h"

class RVerticalPositionerWidget;

RCLASS()
class WHENGINE_API RContextMenuWindow: public RWindow
{
    ROBJECT
public:
    RContextMenuWindow();

    struct SContextMenuItem
    {
        CString Text;
        TDelegate<void> OnClicked;
        TVector<SContextMenuItem> SubMenus;
    };
    
    void AddItem(const SContextMenuItem& InNewItem);

    static float GetItemHeight()
    {
        return 20;
    }

    uint32_t GetItemCount();


    static RWindowPtr CreateContextMenu(
        RWindowPtr ParentWindow
        ,const TVector<SContextMenuItem>& InItems
        ,const SIntPoint & InWindowPosition);

    static RWindowPtr CreateContextMenuAtMouse(
        RWindowPtr ParentWindow
        ,const TVector<SContextMenuItem>& InItems);

protected:
    TWeakObjectPtr<RVerticalPositionerWidget> Container;

    TWeakObjectPtr<RContextMenuWindow> CurrentSubMenu;
    uint32_t CurrentItemIndex=0;

    SRect GetKeepAliveRect()
    {
        //return current item rect
        SRect KeepAliveRect;
        KeepAliveRect.Min.X=0;
        KeepAliveRect.Min.Y=GetItemHeight()*CurrentItemIndex;

        KeepAliveRect.Extent.X=GetWindowSize().X;
        KeepAliveRect.Extent.Y=GetItemHeight();

        return KeepAliveRect;
    }
    TDelegate<SRect> KeepAliveRectDelegate;
    void AttchCurrentSubMenu();
};